import { addStore, actGetStore } from '@/pages/api'
export default {
	data() {
		return {
			shopsId: '',
			rules: {
				shopName: [
					{ required: true, message: '请输入店铺名称', trigger: 'blur' },
				],
				shopOwner: [
					{ required: true, message: '请输入主旺旺ID', trigger: 'change' }
				],
			},
			itemSpell: '',
			dialogVisible: false,
			formLabelAlign: {
				name: '',
				id: ''
			},
			labelPosition: 'top',
			imgList: [
				{
					img: require('@/images/tb.png'),
					text: '淘宝',
					spell: 'taobao',
					key: 1
				},
				{
					img: require('@/images/tm.png'),
					text: '天猫',
					spell: 'tianmao',
					key: 2
				},
				{
					img: require('@/images/jd.png'),
					text: '京东',
					spell: 'jingdong',
					key: 3
				},
				{
					img: require('@/images/pdd.png'),
					text: '拼多多',
					spell: 'pinduoduo',
					key: 4
				}],
			noc: {
				backgroundImage: "url(" + require("../../images/seds.png") + ")",
			},
			firstPage: true,
			isActive: true,
			params: {
				platform: '',
			},
			dataList: [],
			formLabelAlign: {
				platform: '',
				shopName: '',
				shopOwner: '',
			},
		}
	},
	methods: {
		itemClick(item) {
			this.params.platform = item.key
			this.formLabelAlign.platform = item.key
			this.itemSpell = item.spell
			this.init()
		},
		//下一步
		nextStep() {
      if(this.shopsId == ''){
        this.$message({
           message:'请选择店铺',
           type:'warning'
        })
        return
      }
			this.$router.push({name:'SetUpInfo',params:{shopsId:this.shopsId}})
		},
		//点击弹框
		handleClose(done) {
			this.$confirm('确认关闭？')
				.then(_ => {
					done();
				})
				.catch(_ => { });
		},
		//添加店铺
		addStore() {
			if (this.formLabelAlign.platform == '') {
				this.$message({
					message: "请先选择平台",
					type: 'warning'
				})
			} else {
				this.dialogVisible = true
			}
		},
		//将选择店铺的接口封装起来，在两个地方调用
		init() {
			actGetStore(this.params).then(res => {
				this.dataList = res.data.shop
			})
		},
		//点击确定，添加店铺
		confirm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					addStore(this.formLabelAlign).then(res => {
						if (res.code == 0) {
							this.$message({
								message: '添加店铺成功',
								type: "success"
							})
							this.dialogVisible = false
							this.init()
						} else {
							this.$message({
								message: res.msg,
								type: 'error'
							})
						}
					})
				} else {
					return false;
				}
			});
		},
	},
	created() {
		this.shopId = ''
	}
}
